package org.lewis.demo.controller;

import com.fasterxml.jackson.databind.JsonNode;
import org.lewis.demo.prop.OAProperties;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

@RequestMapping("wechat")
@RestController
public class WeChatController {

    private final OAProperties prop;
    private final WebClient webClient = WebClient.create();

    public WeChatController(OAProperties prop) {
        this.prop = prop;
    }

    @GetMapping("accessToken")
    public Mono<JsonNode> getAccessToken() {
        return this.webClient.get().uri(this.prop.getUrl().getGetAccessToken(), this.prop.getAppId(), this.prop.getAppSecret())
                .retrieve().bodyToMono(JsonNode.class);
    }

}
